package com.ozo.boot.common.sms.service;

import org.dromara.sms4j.api.SmsBlend;
import org.dromara.sms4j.api.callback.CallBack;
import org.dromara.sms4j.api.entity.SmsResponse;
import org.dromara.sms4j.core.factory.SmsFactory;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * 短信服务类
 *
 * @author qiangesoft
 * @date 2024-09-06
 */
public class SmsServiceImpl implements SmsService {

    @Override
    public String getSupplier(String configId) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        return smsBlend.getSupplier();
    }

    @Override
    public boolean sendMessage(String configId, String phone, String message) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        SmsResponse smsResponse = smsBlend.sendMessage(phone, message);
        return smsResponse.isSuccess();
    }

    @Override
    public boolean sendMessage(String configId, String phone, LinkedHashMap<String, String> messages) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        SmsResponse smsResponse = smsBlend.sendMessage(phone, messages);
        return smsResponse.isSuccess();
    }

    @Override
    public boolean sendMessage(String configId, String phone, String templateId, LinkedHashMap<String, String> messages) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        SmsResponse smsResponse = smsBlend.sendMessage(phone, templateId, messages);
        return smsResponse.isSuccess();
    }

    @Override
    public void sendMessageAsync(String configId, String phone, String message) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        smsBlend.sendMessageAsync(phone, message);
    }

    @Override
    public void sendMessageAsync(String configId, String phone, String templateId, LinkedHashMap<String, String> messages) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        smsBlend.sendMessageAsync(phone, templateId, messages);
    }

    @Override
    public void sendMessageAsync(String configId, String phone, String message, CallBack callBack) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        smsBlend.sendMessageAsync(phone, message, callBack);
    }

    @Override
    public void sendMessageAsync(String configId, String phone, String templateId, LinkedHashMap<String, String> messages, CallBack callBack) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        smsBlend.sendMessageAsync(phone, templateId, messages, callBack);
    }

    @Override
    public boolean sendMassMessage(String configId, List<String> phones, String message) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        SmsResponse smsResponse = smsBlend.massTexting(phones, message);
        return smsResponse.isSuccess();
    }

    @Override
    public boolean sendMassMessage(String configId, List<String> phones, String templateId, LinkedHashMap<String, String> messages) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        SmsResponse smsResponse = smsBlend.massTexting(phones, templateId, messages);
        return smsResponse.isSuccess();
    }

    @Override
    public void sendMassMessageAsync(String configId, List<String> phones, String message) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        for (String phone : phones) {
            smsBlend.sendMessageAsync(phone, message);
        }
    }

    @Override
    public void sendMassMessageAsync(String configId, List<String> phones, String templateId, LinkedHashMap<String, String> messages) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        for (String phone : phones) {
            smsBlend.sendMessageAsync(phone, templateId, messages);
        }
    }

    @Override
    public void sendMassMessageAsync(String configId, List<String> phones, String message, CallBack callBack) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        for (String phone : phones) {
            smsBlend.sendMessageAsync(phone, message, callBack);
        }
    }

    @Override
    public void sendMassMessageAsync(String configId, List<String> phones, String templateId, LinkedHashMap<String, String> messages, CallBack callBack) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        for (String phone : phones) {
            smsBlend.sendMessageAsync(phone, templateId, messages, callBack);
        }
    }

    @Override
    public void sendDelayedMessage(String configId, String phone, String message, Long delayedTime) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        smsBlend.delayedMessage(phone, message, delayedTime);
    }

    @Override
    public void sendDelayedMessage(String configId, String phone, String templateId, LinkedHashMap<String, String> messages, Long delayedTime) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        smsBlend.delayedMessage(phone, templateId, messages, delayedTime);
    }

    @Override
    public void sendMassDelayedMessage(String configId, List<String> phones, String message, Long delayedTime) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        smsBlend.delayMassTexting(phones, message, delayedTime);
    }

    @Override
    public void sendMassDelayedMessage(String configId, List<String> phones, String templateId, LinkedHashMap<String, String> messages, Long delayedTime) {
        SmsBlend smsBlend = SmsFactory.getSmsBlend(configId);
        smsBlend.delayMassTexting(phones, templateId, messages, delayedTime);
    }

}
